<?php

/**
 * seo actions.
 *
 * @package    sf_sandbox
 * @subpackage seo
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2288 2006-10-02 15:22:13Z fabien $
 */
class sitemapActions extends sfActions
{
    public function executeMain()
    {
        //get all active users
        $c = new Criteria();
        $c->add(UserPeer::STATUS_ID, MyConstants::STATUS_APPROVED);
        $users = UserPeer::doSelect($c);
        $stringXml = '';
        $stringXml .= JSitemap::getHeaderIndex();
        /* @var $user User */
        foreach( $users as $user )
        {
            $stringXml .= JSitemap::getSitemapsLoc("http://interateitis.lt/sitemap/" . $user->getId() . '.xml');
            // @todo: sitemap with slug blog title
        }
        
        $stringXml .= JSitemap::getFooterIndex();
        return $this->renderText($stringXml);
    }
    /**
     * 
     * one users sitemap by id
     */
    public function executeFor()
    {
        $id = (int)$this->getRequestParameter('user', 0);
        $stringXml = '';
        $stringXml .= JSitemap::getHeader();
        
        //write content
        $arLinks = Blog::linksByUserId($id);
        foreach( $arLinks as $link )
        {
            $stringXml .= JSitemap::getUrlSitemap($link['loc'], $link['lastmod'], $link['changefreq'], $link['priority']) . "\n";
        }
        
        $stringXml .= JSitemap::getFooter();
        return $this->renderText($stringXml);
    }
}
